<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>水平居中布局解决方案4-绝对定位position</title>
  <style>
   /* html： 行内inline  块级：block  文字 
    position: absolute;
    left:50%;
    +  margin-left: -100px;  负值技巧
    +  transform: translateX(-50%);   CSS3 兼容性不太好
    
    position: absolute;
    left:0;
    right:0;
    margin:auto;
   */
     #parent{
       width: 500px;
       height: 500px;
       background-color: red;
       text-align: center;
       position: relative;
     }
     #child{
       position: absolute;
       left:0;
       right:0;
       margin:auto;
       width: 200px;
       height: 200px;
       background-color: blue;
     }

  </style>
</head>

<body>
  <!-- 定义父级元素 -->
  <div id="parent">
    <!-- 定义子级元素 -->
    <div id="child"></div>
  </div>
</body>

</html>